const Sequelize = require('sequelize');
module.exports = function (sequelize, DataTypes) {
    return sequelize.define(
        't_social_security',
        {
            id: {
                autoIncrement: true,
                type: DataTypes.BIGINT,
                allowNull: false,
                primaryKey: true,
                comment: '社保ID',
            },
            emp_id: {
                type: DataTypes.BIGINT,
                allowNull: false,
                comment: '员工ID',
                references: {
                    model: 't_employee',
                    key: 'id',
                },
            },
            pay_month: {
                type: DataTypes.DATEONLY,
                allowNull: false,
                comment: '缴纳月份',
            },
            base_amount: {
                type: DataTypes.DECIMAL(10, 2),
                allowNull: false,
                comment: '缴费基数',
            },
            personal_social: {
                type: DataTypes.DECIMAL(10, 2),
                allowNull: true,
                comment: '个人社保金额',
            },
            company_social: {
                type: DataTypes.DECIMAL(10, 2),
                allowNull: true,
                comment: '公司社保金额',
            },
            personal_fund: {
                type: DataTypes.DECIMAL(10, 2),
                allowNull: true,
                comment: '个人公积金金额',
            },
            company_fund: {
                type: DataTypes.DECIMAL(10, 2),
                allowNull: true,
                comment: '公司公积金金额',
            },
            status: {
                type: DataTypes.TINYINT,
                allowNull: false,
                defaultValue: 0,
                comment: '状态：0-未缴，1-已缴',
            },
            create_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
            update_time: {
                type: DataTypes.DATE,
                allowNull: false,
                defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP'),
            },
        },
        {
            sequelize,
            tableName: 't_social_security',
            timestamps: false,
            indexes: [
                {
                    name: 'PRIMARY',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'id' }],
                },
                {
                    name: 'uk_emp_month',
                    unique: true,
                    using: 'BTREE',
                    fields: [{ name: 'emp_id' }, { name: 'pay_month' }],
                },
                {
                    name: 'idx_pay_month',
                    using: 'BTREE',
                    fields: [{ name: 'pay_month' }],
                },
            ],
        },
    );
};
